#include "stdafx.h"
#include "StudentManagement.h"
#include "StudentDB.h"
#include "Student.h"
#include "Grade.h"
#include "Takes.h"
#include "TakesDB.h"
#include "UserDB.h"
#include "User.h"


StudentManagement::StudentManagement()
{
}

Student StudentManagement::CheckOneStudentMess(const string &id)//查看一个学生的信息
{
	StudentDB sDB;
	Student messOne = sDB.selectById(id);
	return messOne;
}

list<Student> StudentManagement::CheckAllStudentMess()//查看所有学生的信息
{
	StudentDB sDB;
	list<Student> messAll = sDB.selectAll();
	return messAll;
}

string StudentManagement::AddStudent(string &id, string &name, string &sex, string &class_name, string &dept_name,string &pw)
{//增添学生
	UserDB user;
	StudentDB stu;
	Student t(id, name, sex, class_name, dept_name);

	if ((stu.selectById(id)).getName() != "")//即已存在相同id号的学生
	{
		return "已存在该ID号的学生，请重新输入";
	}
	else
	{
		stu.insert(t);
		User u(id, "学生", pw);
		user.insert(u);
		return "添加学生信息成功";
	}
}

string StudentManagement::DeleteStudent(string &id)//删除学生
{
	StudentDB sDB;
	Student stu = sDB.selectById(id) ;
	TakesDB tDB;
	list<Takes> t = tDB.selectAllByStudentId(id);
	UserDB uDB;

	if (stu.getId() == "")//判断ID号是否存在
	{
		return "该ID号不存在，无法删除!";
	}
	else if (t.size()!=0)//存在takes中则不能删除
	{
		return "该学生存在成绩，不可删除!";
	}
	else//可以删除的
	{
		sDB.deleteById(id);
		uDB.deleteByUserId(id);
		return "成功删除 !";
	}
}

StudentManagement::~StudentManagement()
{
}
